sCanvas.fn.extend(true, {
	
	//stores currently animated objects
	animated: [ ],

	//count of currently animated objects
	animatedCount: 0,

	//true if canvas is currently performing an animation
	isAnimating: false,

	//registers animated object
	addAnimatedObject: function(obj) {
		this.animated.push(obj);
		this.animatedCount++;
		//TODO: handle adding already added object
		//if animation is not running, run it
		if (!this.isAnimating) {
			this.isAnimating = true;
			this.runAnimation();
		}
	},

	//unregisters animated object
	removeAnimatedObject: function(obj) {
		delete this.animated[this.animated.indexOf(obj)];
		this.animatedCount--;
		//TODO: handle removing object which was not added
		//if there is no animated object, stop animating
		if (this.animatedCount === 0) {
			this.isAnimating = false;
			this.animated = [ ];
		}
	},

	//performs animation frame by frame
	runAnimation: function() {
		var i,
			sc = this,
			time = sCanvas.now();

		//prevents requesting next frame, if there is no animated object
		//also prevents needless repainting - since we are requesting
		//frame and then we count if it is needed at all
		//so there is always one "blank" requested frame at the end
		//of animation when nothing is done
		//TODO: think if this can be fixed
		if (this.isAnimating) {
			window.requestAnimationFrame(function() {
				sc.runAnimation();
			});

			//update all animated objects attributes
			for (i in this.animated) {
				this.animated[i].stepAnimation(time);
			}
			this.repaint();
		}
	}

});